<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8"/>
    <title>广告位</title>
    <meta name="description" content="overview & stats"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="static/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="static/css/bootstrap-responsive.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="static/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="static/css/ace.min.css"/>
    <link rel="stylesheet" href="static/css/ace-responsive.min.css"/>
    <link rel="stylesheet" href="static/css/ace-skins.min.css"/>
    <script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
    <!--提示框-->
    <script type="text/javascript" src="static/js/jquery.tips.js"></script>
</head>

<script type="text/javascript">
    $(function () {
        top.hangge();
    });

    //保存
    function save() {
        var title = $("#title").val();
        if (title == "") {
            $("#title").tips({
                side: 3,
                msg: '请输入名称',
                bg: '#AE81FF',
                time: 2
            });
            $("#title").focus();
            return false;
        }
        var imageUrl = $("#imageUrl").val();
        if (imageUrl == "") {
            $("#imageUrl").tips({
                side: 3,
                msg: '请输入广告图片链接地址',
                bg: '#AE81FF',
                time: 2
            });
            $("#imageUrl").focus();
            return false;
        }

        /*if ($("#adversterId").val() ==""){
            alert("请选择广告商");
            return false;
        }
        if ($("#adversterSlotId").val() ==""){
            alert("请选择广告位");
            return false;
        }
        if ($("#redirectType").val() ==""){
            alert("请选择广告类型");
            return false;
        }
        if ($("#status").val() ==""){
            alert("请选择广告状态");
            return false;
        }
        if ($("#weight").val() ==""){
            alert("请选择广告权重");
            return false;
        }
        if ($("#priority").val() ==""){
            alert("请选择广告优先级");
            return false;
        }*/

        $.get("pxAdversterConfiguration/checkTitle",
            {"id": $("#id").val(),"title": title},
            function (data) {
                if (data.code == 200) {
                    $("#menuForm").submit();
                    $("#zhongxin").hide();
                    $("#zhongxin2").show();
                } else {
                    $("#title").tips({
                        side: 3,
                        msg: data.msg,
                        bg: '#AE81FF',
                        time: 2
                    });
                    $("#title").focus();
                    return false;
                }
            });
    }
</script>

<body>
<form action="pxAdversterConfiguration/edit" name="menuForm" id="menuForm" method="post" enctype="multipart/form-data">
    <input type="hidden" id="id" name="id" value="${adConfiguration.id}">
    <input type="hidden" name="advertsterName" id="advertsterName" value="${adConfiguration.advertsterName}" style="width:200px;"/>
    <input type="hidden" name="adversterSlotName" id="adversterSlotName"  value="${adConfiguration.adversterSlotName}" style="width:200px;"/>
    <div id="zhongxin" class="zhongxin-cla">
        <table>
            <tr>
                <td>
                    <font color='red'>*</font>
                    <span>标题：</span>
                    <input type="text" name="title" id="title" style="width:200px;" value="${adConfiguration.title}" placeholder="广告标题"/>
                </td>
            </tr>
            <tr>
                <td>
                    <%--<font color='red'>*</font>--%>
                    <span>广告商：</span>
                    <select id="adversterId" name="adversterId" data-values="${adversters}" data-placeholder="请选择广告商"
                            style="vertical-align:top;width: 120px;" onchange="settingAdversterName()">
                        <option value="">选择广告商</option>
                        <c:forEach items="${adversters}" var="adverster">
                            <option value="${adverster.id}"
                                    <c:if test="${adverster.id eq adConfiguration.adversterId}">selected</c:if> >${adverster.name}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <%--<font color='red'>*</font>--%>
                    <span>广告位：</span>
                    <select id="adversterSlotId" name="adversterSlotId" data-values="${adversterSlotId}" data-placeholder="请选择广告位"
                            style="vertical-align:top;width: 120px;" onchange="settingAdversterSlotName()">
                        <option value="">选择广告位</option>
                        <c:forEach items="${adversterSlots}" var="adversterSlot">
                            <option value="${adversterSlot.id}"
                                    <c:if test="${adversterSlot.id eq adConfiguration.adversterSlotId}">selected</c:if>>${adversterSlot.name}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <%--<font color='red'>*</font>--%>
                    <span>内容：</span>
                    <input type="text" name="content" id="content" style="width:200px;" value="${adConfiguration.content}" placeholder="广告内容"/>
                </td>
            </tr>
            <tr>
                <td>
                    <font color='red'>*</font>
                    <span>广告图地址：</span>
                    <input type="text" name="imageUrl" id="imageUrl" style="width:300px;" value="${adConfiguration.imageUrl}" placeholder="广告图地址"/>
                </td>
            </tr>
            <tr>
                <td>
                    <%-- <font color='red'>*</font>--%>
                    <span>跳转地址：</span>
                    <input type="text" name="redirectUrl" id="redirectUrl" style="width:300px;" value="${adConfiguration.redirectUrl}" placeholder="跳转地址"/>
                </td>
            </tr>
            <tr>
                <td>
                   <%-- <font color='red'>*</font>--%>
                    <span>广告类型：</span>
                    <select id="redirectType" name="redirectType" data-placeholder="请选择广告类型" style="vertical-align:top;width:200px;">
                        <option value="">选择广告类型</option>
                        <option value="0" <c:if test="${adConfiguration.redirectType != null && adConfiguration.redirectType == 0}">selected</c:if>>产品广告</option>
                        <option value="1" <c:if test="${adConfiguration.redirectType != null && adConfiguration.redirectType == 1}">selected</c:if>>会员充值广告</option>
                        <option value="2" <c:if test="${adConfiguration.redirectType != null && adConfiguration.redirectType == 2}">selected</c:if>>金币充值广告</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <%--<font color='red'>*</font>--%>
                    <span>广告状态：</span>
                    <select id="status" name="status" data-placeholder="请选择停启用状态" style="vertical-align:top;width:200px;">
                        <option value="">选择停启用状态</option>
                        <option value="0" <c:if test="${adConfiguration.status != null && adConfiguration.status == 0}">selected</c:if>>停用</option>
                        <option value="1" <c:if test="${adConfiguration.status != null && adConfiguration.status == 1}">selected</c:if>>启用</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                   <%-- <font color='red'>*</font>--%>
                    <span>用户类型：</span>
                    <select id="userType" name="userType" data-placeholder="请选择用户类型" style="vertical-align:top;width:200px;">
                        <option value="">选择用户类型</option>
                        <option value="0" <c:if test="${adConfiguration.userType != null && adConfiguration.userType == 0}">selected</c:if>>非会员</option>
                        <option value="1" <c:if test="${adConfiguration.userType != null && adConfiguration.userType == 1}">selected</c:if>>会员</option>
                        <option value="2" <c:if test="${adConfiguration.userType != null && adConfiguration.userType == 2}">selected</c:if>>所有用户</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                   <%-- <font color='red'>*</font>--%>
                    <span>广告权重：</span>
                    <select id="weight" name="weight" data-placeholder="请选择权重" style="vertical-align:top;">
                        <option value="">选择权重</option>
                        <c:forEach var="i" begin="1" end="10">
                            <option value="${i}" <c:if test="${adConfiguration.weight != null && adConfiguration.weight == i}">selected</c:if>>${i}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                   <%-- <font color='red'>*</font>--%>
                    <span>广告优先级：</span>
                    <select id="priority" name="priority" data-placeholder="请选优先级" style="vertical-align:top;">
                        <option value="">请选优先级</option>
                        <c:forEach var="i" begin="1" end="5">
                            <option value="${i}" <c:if test="${adConfiguration.priority != null && adConfiguration.priority == i}">selected</c:if>>${i}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <%-- <font color='red'>*</font>--%>
                    <span>广告支持App的最低版本：</span>
                    <input type="text" name="version" id="version" style="width:200px;" value="${adConfiguration.version}" placeholder="广告支持App的最低版本"/>
                </td>
            </tr>
            <tr>
                <td style="text-align: center; padding-top: 10px;">
                    <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                    <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                </td>
            </tr>
        </table>
    </div>
    <div id="zhongxin2" class="center" style="display:none">
        <br/><br/><br/><img src="static/images/jiazai.gif"/><br/>
        <h4 class="lighter block green"></h4>
    </div>
</form>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript">
    //设置广告商名字
    function settingAdversterName() {
        var  advertsterName = document.getElementById('advertsterName');
        var  adversterId = document.getElementById('adversterId').value;
        // 遍历 adversters 并根据 adversterId 过滤选项
        <c:forEach items="${adversters}" var="adverster">
        if ("${adverster.id}" == adversterId) {
            advertsterName.value = "${adverster.name}";
        }
        </c:forEach>
    }

    //设置广告位名字
    function settingAdversterSlotName() {
        var  adversterSlotName = document.getElementById('adversterSlotName');
        var  adversterSlotId = document.getElementById('adversterSlotId').value;
        // 遍历 adversters 并根据 adversterId 过滤选项
        <c:forEach items="${adversterSlots}" var="adversterSlot">
        if ("${adversterSlot.id}" == adversterSlotId) {
            adversterSlotName.value = "${adversterSlot.name}";
        }
        </c:forEach>
    }
</script>
</body>
</html>